Python

socket.gaierror: [Errno 11001] getaddrinfo failed- Python Error

socket.gaierror: [Errno 11001] getaddrinfo failed- Python Error, someone asked me to explain?

CODE:

def get_ssl_details(domain):
    context = ssl.create_default_context()
    conn = context.wrap_socket(socket.socket(socket.AF_INET), server_hostname=domain)
    conn.connect((domain, 443))
    cert = conn.getpeercert() 

    issuer = dict(x[0] for x in cert['issuer'])
    subject = dict(x[0] for x in cert['subject'])
    expire_date = datetime.datetime.strptime(cert['notAfter'], '%b %d %H:%M:%S %Y %Z')
    days_remaining=expire_date-datetime.datetime.utcnow()

    return {
        'issuer': issuer,
        'subject': subject,
        'expire_date': expire_date,
        'days_remain':days_remaining
    }

When I m running the above code and entering the input domain https://www.chiptrolls.com/ . I got this following error while running the python program "socket.gaierror: [Errno 11001] getaddrinfo failed".

addrinfo

SOLUTION:

conn.connect((domain, 443)) expects only domain from the URL without the (http or https) protocol. So the below code extract the domain from the input URL from https://www.chiptrolls.com/ to www.chiptrolls.com.

    parsed_url=urlparse(domain)
    domain=parsed_url.netloc

VIDEO GUIDE:

Post your comments / questions